local lsp_hujuan = fk.CreateSkill {
    name = "lsp_hujuan",
    dynamic_desc = function(self, player, lang)
        return "lsp_hujuan_skill:" .. player:getMark(self.name)
    end,
}

Fk:loadTranslationTable {
    ["lsp_hujuan"] = "狐眷",
    [":lsp_hujuan"] = "每局游戏限零次，你可以将手牌调整至体力上限，回复一点体力，获得武将牌上的所有牌，然后此技能失效直到回合结束(你每失去手牌、装备，或获得手牌累计15张后，此技能增加一次使用次数)。",

    [":lsp_hujuan_skill"] = "（还剩{1}次）你可以将手牌调整至体力上限，回复一点体力，获得武将牌上的所有牌。",
    ["@@lsp_hujuan-turn"] = "狐眷失效",
}
lsp_hujuan:addEffect("active", {
    anim_type = "drawcard",
    card_num = 0,
    target_num = 0,
    prompt = "你可以将手牌调整至体力上限，回复一点体力，获得武将牌上的所有牌",
    card_filter = Util.FalseFunc,
    can_use = function(self, player)
        local num = {}
        for _, t in pairs(player.special_cards) do
            table.insertTableIfNeed(num, t)
        end
        return player:usedSkillTimes(lsp_hujuan.name, Player.HistoryPhase) < player:getMark(self.name) and
            (player:isWounded() or player.maxHp ~= player:getHandcardNum() or #num > 0) and
            player:getMark("@@lsp_hujuan-turn") == 0
    end,
    on_use = function(self, room, effect)
        local player = effect.from
        room:removePlayerMark(player, lsp_hujuan.name, 1)
        room:setPlayerMark(player, "@@lsp_hujuan-turn", 1)
        local n = math.abs(player.maxHp - player:getHandcardNum())
        if player.maxHp > player:getHandcardNum() then
            player:drawCards(n, lsp_hujuan.name)
        elseif player.maxHp < player:getHandcardNum() then
            room:askToDiscard(player, {
                min_num = n,
                max_num = n,
                include_equip = false,
                skill_name = lsp_hujuan.name,
                cancelable = false,
            })
        end
        if player:isWounded() then
            room:recover({
                who = player,
                num = 1,
                recoverBy = player,
                skillName = lsp_hujuan.name
            })
        end
        local num = {}
        for _, t in pairs(player.special_cards) do
            table.insertTableIfNeed(num, t)
        end
        if #num > 0 then
            room:moveCards({
                from = player,
                ids = num,
                to = player,
                toArea = Card.PlayerHand,
                moveReason = fk.ReasonJustMove,
                proposer = player,
                skillName = self.name,
            })
        end
    end,
})
lsp_hujuan:addEffect(fk.AfterCardsMove, {
    can_refresh = function(self, event, target, player, data)
        return player:hasSkill(lsp_hujuan.name, true) and player:getMark("@@lsp_hujuan-turn") == 0
    end,
    on_refresh = function(self, event, target, player, data)
        local room = player.room
        if event == fk.AfterCardsMove then
            local i = 0
            for _, move in ipairs(data) do
                if move.from == player then
                    for _, info in ipairs(move.moveInfo) do
                        if info.fromArea == Card.PlayerEquip or info.fromArea == Card.PlayerHand then
                            i = i + 1
                        end
                    end
                end
                if move.to == player and move.toArea == Card.PlayerHand then --获得牌计数
                    i = i + #move.moveInfo
                end
            end
            if i > 0 then
                for _ = 1, i, 1 do
                    room:addPlayerMark(player, "lsp_hujuan_num", 1)
                    if player:getMark("lsp_hujuan_num") > 14 then
                        room:setPlayerMark(player, "lsp_hujuan_num", 0)
                        room:addPlayerMark(player, lsp_hujuan.name, 1)
                    end
                end
            end
        end
    end,
})

return lsp_hujuan
